package com.hf.fetch

import com.hf.constant.OrderLunchConst
import com.hf.security.OrderUser

class UserFetchSummary {

	OrderUser user
	FetchGroup fetchGroup

	BigDecimal ratio
	int allFetchedCount
	int allOrderedCount
	
	boolean notFetch

	static constraints = {
		user(nullable:false, unique:true)
		fetchGroup(nullable:true)

		ratio(nullable:true)
		allFetchedCount(nullable:false)
		allOrderedCount(nullable:false)
		
		notFetch(nullable:false)
	}

	static mapping = { sort ratio : "desc" }

	BigDecimal getRatio() {
		// (order + 3)/ (fetch + 1)
		return (BigDecimal)(allOrderedCount + OrderLunchConst.FETCH_RATIO_AJUST_ZERO) / (allFetchedCount + 1)
	}

	String toString() {
		return "$user.name - $ratio"
	}
}
